const  FS = require('fs'),  Form = require('formidable'),
       Utility = require('../libs/utility');



module.exports = function (request) {

    return  new Promise(function (resolve, reject) {

        var form = new Form.IncomingForm();

        form.multiples = true;
        form.uploadDir = Utility.fromCWD('.temp');

        if (! FS.existsSync( form.uploadDir ))
            FS.mkdirSync( form.uploadDir );

        form.parse(request,  function(error) {

            if ( error )  return  reject( error );

            request.params = arguments[1];

            request.files = arguments[2];

            resolve();
        });
    })
};
